﻿using System;
using Microsoft.EntityFrameworkCore;
using SaiLing.Domain.Persistence.Relational;

namespace SaiLing.SingleSignOn.Repository
{
    public static class DbContextExtend
    {
        public static void AttachUpdated<T>(this DbContext obj, T objectDetached) where T :  IEntity
        {
            if (objectDetached == null) throw new ArgumentNullException();
            if (obj.Entry<T>(objectDetached).State == EntityState.Detached)
            {
                obj.Set<T>().Attach(objectDetached);
            }
        }
    }
}
